import requests
import logging
class Tesryk():
    uid=""
    sid=""
    def setup_method(self):
        print("准备执行测试用例")
    def teardown_method(self):
        print("执行结束")
#登录
    def test_login(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            body={"phone":"13811033965","pwd":"123456Aa"}
            r=requests.post(url=url,json=body)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#新增加一个收货地址，信息参数正确增加成功并返回成功信息
    def test_addReceiveAddress(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"18765539265",
                   "address":"北京 海淀区 八维",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#未填写收货人真实姓名，添加失败并返回失败信息
    def test_addReceiveAddress2(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"",
                   "phone":"18765539265",
                   "address":"北京 海淀区 八维",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#未填写手机号码，添加失败并返回失败信息
    def test_addReceiveAddress3(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"",
                   "address":"北京 海淀区 八维",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#未填写收货地址，添加失败并返回失败信息
    def test_addReceiveAddress4(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"18765539265",
                   "address":"",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#填写收货地址不准确，添加失败并返回失败信息
    def test_addReceiveAddress5(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"18765539265",
                   "address":"北京",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#未填写邮政编码，添加失败并返回失败信息
    def test_addReceiveAddress6(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"18765539265",
                   "address":"北京 海淀区 八维",
                   "zipCode":""}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#填写的邮政编码错误，添加失败并返回失败信息
    def test_addReceiveAddress7(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"18765539265",
                   "address":"北京 海淀区 八维",
                   "zipCode":"000"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#填写的手机号码错误，添加失败并返回失败信息
    def test_addReceiveAddress8(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"1876",
                   "address":"北京 海淀区 八维",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#填写的地址错误，添加失败并返回失败信息
    def test_addReceiveAddress9(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={"realName":"小张",
                   "phone":"18765539265",
                   "address":"大海",
                   "zipCode":"101010"}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#账号未登录，添加失败并返回失败信息
    def test_addReceiveAddress10(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/addReceiveAddress"
            body={}
            headers=Tesryk.uid
            headers2=Tesryk.sid
            r=requests.post(url=url,json=body,headers=headers,headers2=headers2)
            logging.info(r.json())
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]





